import java.util.*;
public class Solution
{
    int[] dp = new int[1010];
    public int knapsack (int V, int n, int[][] vw) {
        for(int i = 0; i < n; i++) {
            for(int j = V; j >= vw[i][0]; j--) {
                dp[j] = Math.max(dp[j], dp[j - vw[i][0]] + vw[i][1]);
            }
        }
    return dp[V];
    }
}

